﻿//
//  Windows_libc
//
//  Created by  cc_team(陈旭，陈曦) qq:511272827.
//  Copyright 2011 cc_team. All rights reserved.
//
#ifndef CC_PRINT_H
#define CC_PRINT_H

#include "cc_common.h"
#include "cc_stdlib.h"
#include "cc_for.h"
#include <stdio.h>

#ifdef __cplusplus
// print all elements of an array , with new line at the end of each element
#define PRINT_ARRAY(arr, n)		 \
		do						 \
		{						 \
			FOR(0, n, 1)	 \
			{					 \
				COUT_ENDL(arr[i])\
			}					 \
		}while(0);

// it's better than PRINT_ARRAY, because it omits the size of the array, but you should
// make sure the argument "arr" is really an array!
#define PRINT_ARRAY_EX(arr)										 \
		do														 \
		{														 \
			FOR(0, (int)(sizeof(arr) / sizeof(arr[0]) - 1), 1)	 \
			{													 \
				COUT_ENDL(arr[i])								 \
			}													 \
		}while(0);
#endif

// print success or fail str
#define PRINT_SUCCESS				printf("Successfully!")
#define PRINT_SUCCESS_STR(str)		printf(str"Successfully!")
#define PRINT_FAILED				printf("Failed!")
#define PRINT_FAILED_STR(str)		printf(str"Failed!")

// enter or leave a function
#define PRINT_ENTER_FUNC(func)		printf("enter func"func)
#define PRINT_LEAVE_FUNC(func)		printf("leave func"func)

// new line
#define	PRINT_NEW_LINE				printf("\n")

// print seperators like stars, a new line will print, too.
#define PRINT_STARTS(times)			\
	{							\
		int i = 0;				\
		for(; i < times; ++i)	\
		{						\
			printf("*");		\
		}						\
		PRINT_NEW_LINE;			\
	}

#define PRINT(ch, times)		\
	{							\
		int i = 0;				\
		for(; i < times; ++i)	\
		{						\
			printf("%c", ch);	\
		}						\
		PRINT_NEW_LINE;			\
	}

__BEGIN_DECLS

// I am sorry, but it has some bugs
void cc_printEachChar(char *str);

// a simple func like printf func;it just stands for %d, %x output,
// also, it is not complete, it calls C func printf.
int cc_simple_printf(
	const char *format,
	...
);

__END_DECLS

#endif
